package indi.dbfmp.oio.oauth.core.controller;


import cn.hutool.core.util.StrUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import indi.dbfmp.oio.oauth.core.enums.MetricName;
import indi.dbfmp.oio.oauth.core.enums.MetricTags;
import indi.dbfmp.oio.oauth.core.innerService.ISystemInnerService;
import indi.dbfmp.oio.oauth.core.service.impl.SystemService;
import indi.dbfmp.web.common.dto.CommonResult;
import io.micrometer.core.annotation.Timed;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import indi.dbfmp.oio.oauth.core.entity.System;

import org.springframework.web.bind.annotation.RestController;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author dbfmp
 * @since 2021-03-14
 */
@Slf4j
@RestController
@RequiredArgsConstructor
@RequestMapping("/system")
public class SystemController {

    private final SystemService systemService;

    /**
     * 查
     * @param configKey
     * @return
     */
    @Timed(value = MetricName.REQ_TIMED,description = "根据key获取系统配置",extraTags = {MetricTags.URL,"/system/getListByKey/{configKey}"},histogram = true)
    @RequestMapping("/getListByKey/{configKey}")
    public CommonResult<?> getListByKey(@PathVariable("configKey") String configKey) {
        if (StrUtil.isBlank(configKey)) {
            return CommonResult.success(null);
        }
        return CommonResult.success(systemService.getSysConfigListByKey(configKey));
    }

    /**
     * 查
     * @param configKey
     * @return
     */
    @Timed(value = MetricName.REQ_TIMED,description = "根据key获取系统配置",extraTags = {MetricTags.URL,"/system/getByKey/{configKey}"},histogram = true)
    @RequestMapping("/getByKey/{configKey}")
    public CommonResult<?> getByKey(@PathVariable("configKey") String configKey) {
        if (StrUtil.isBlank(configKey)) {
            return CommonResult.success(null);
        }
        return CommonResult.success(systemService.getSysConfigByKey(configKey));
    }

}
